Private Sub Comando62_Click()
SQL = "Delete * From importacion;" 'Borra los datos de la tabla
CurrentDb.Execute SQL


Dim cn As DAO.Database
Dim rs As DAO.Recordset
 
 DoCmd.TransferText acImportDelim, "Importacion2", "importacion", "C:\Users\MM\Downloads\activity.csv"

    Set cn = CurrentDb
    Set rs = cn.OpenRecordset("Importacion")  'borra el ultimo registro ya que el csv tiene un registro duplicado
    rs.MoveLast
    rs.Delete
        
    rs.Close
    cn.Close
    
    Set rs = Nothing
    Set cn = Nothing
    
    Dim Rst1 As DAO.Recordset, Rst2 As DAO.Recordset
     'Definimos sendas variables para referirnos a los
     'conjuntos de registros correspondientes a las dos tablas
  
     Set Rst1 = CurrentDb.OpenRecordset("importacion")
     Set Rst2 = CurrentDb.OpenRecordset("entreno")
     'Abrimos las dos tablas asignndo sus registros a las variables
     'siendo el primero el que corresponde a la tabla origen
     'y el segundo a la de destino.
       Do While Not Rst1.EOF
         'Para cada registro de la tabla origen
         
             Rst2.AddNew                'Aadimos un registro en la tabla destino
             Rst2!Tiempo = Rst1!Tiempo
             Rst2!Km = Rst1!Distancia
             Rst2!Altura_acumulada = Rst1!Altura_acumulada
             Rst2!Vm = Rst1!Vm
             Rst2!Vmx = Rst1!Vmx
             Rst2!FCm = Rst1!FCm
             Rst2!FCmx = Rst1!FCmx
             Rst2!Cad_Med = Rst1!Cad_Med
             Rst2!Cad_Mx = Rst1!Cad_Mx
             Rst2!TMedia = Rst1!TMedia
             Rst2!Kcal = Rst1!Kcal
             Rst2.Update                'Grabamos el registro
             Rst1.MoveNext                  'Pasamos al siguiente registro de la tabla origen
         
         DoEvents            'Por si acaso entra en bucle y se cuelga
     Loop
  
     Rst1.Close  'Cerramos los recordsets
     Rst2.Close
  
     Set Rst1 = Nothing  'Vaciamos las variables
     Set Rst2 = Nothing
     
DoCmd.OpenForm "ENTRENO"    'Actualiza el formulario
DoCmd.Close                      ' Lo Cierra
DoCmd.OpenForm "ENTRENO"     ' Lo abre
DoCmd.GoToRecord , , acPrevious  ' Se mueve al registro anterior ya que al abrir se posiciona en Nuevo

End Sub
